package com.keya.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.keya.pull.PullStudyRecord;
import com.keya.pull.PullStudyRecordBO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 拉取院方数据记录 Mapper 接口
 * </p>
 *
 * @author hsq
 * @since 2022-08-12
 */
public interface PullStudyRecordMapper extends BaseMapper<PullStudyRecord> {

    @Select({"<script>",
            "  SELECT study_instance_uid FROM pull_study_record WHERE study_instance_uid IN",
            "  <foreach collection=\"studyUIDs\" item=\"uid\" open=\"(\" close=\")\" separator=\",\">",
            "    \"${uid}\"",
            "  </foreach>",
            "</script>",
    })
    List<String> getExistedUIDs(@Param("studyUIDs") List<String> studyUIDs);

    @Select(" select a.*,b.aetitle from pull_study_record a join devices b on a.device_id=b.id  " +
            " ${ew.customSqlSegment} " +
            " limit ${limit} OFFSET ${offset} ")
    List<PullStudyRecordBO> getList(@Param("limit") int limit, @Param("offset") int offset, @Param("ew") QueryWrapper ew);

    @Select(" select count(1) from pull_study_record a join devices b on a.device_id=b.id  " +
            " ${ew.customSqlSegment} ")
    int count(@Param("limit") int limit, @Param("offset") int offset, @Param("ew") QueryWrapper ew);
}
